<template> 
  <el-container class="home_container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <span>学籍管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 页面主体区 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse"> ||| </div>
        <!-- 侧边栏菜单区 -->
        <el-menu
        background-color="#000000"
        text-color="#fff"
        active-text-color="#ffd04b" :unique-opened="true" 
        :collapse="isCollapse" :collapse-transition="false"
        :router="true" :default-active="activePath">
  
        <!-- 一级菜单 -->
        <el-submenu :index="''+item.id" v-for="item in menulist" :key="item.id">
          <!-- 一级菜单模板区域 -->
          <template slot="title">
            <!-- 文本 -->
            <span>{{item.name}}</span>
          </template>

        </el-submenu>  
      </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>

export default {
  name: 'home',
  data(){
    return{
      menulist:[
        {name:"查询所有学生", id:1, path:"list"},
        {name:"增加学生", id:2, path:"add"},
        {name:"更新学生", id:3, path:"update"},
        {name:"删除学生", id:4, path:"delete"},
        {name:"查找学生", id:5, path:"found"},
        {name:"年龄统计", id:6, path:"age"},
        {name:"地区统计", id:7, path:"region"}
      ],
      isCollapse: false,
      activePath:''
    };
  },
  components:{
    
  },
  created(){
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods:{
    logout(){
      this.$router.push("/");
    },
    // 点击按钮，切换菜单的折叠与展开
    toggleCollapse(){
      this.isCollapse = !this.isCollapse;
    },
    // 保存连接的激活状态
    saveNavState(activePath){
        window.sessionStorage.setItem('activePath', activePath);
        this.activePath = activePath;
    },
  }
}
</script>

<style lang='less' scoped>
.home_container{
  height: 100%;
}

.el-header{
  background-color: #000000;
  display: flex;
  justify-content: space-between;
  padding-right: 0;
  padding-left: 42%;
  align-items: center;
  color: #fff;
  font-size: 20px;
}

.el-header div{
  align-items: center;
}

.el-aside {
  background-color: #000000;
}

.el-aside .el-menu{
  border-right: none;
}

.el-main{
  background-color: rgb(224, 224, 224);
}

.toggle-button{
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}

</style>